package com.atguigu.elasticsearch;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.client.indices.GetIndexResponse;

import java.io.IOException;

public class ESIndexSearch {

    public static void main(String[] args) throws IOException {

        RestHighLevelClient esClient =
                new RestHighLevelClient(
                        RestClient.builder(new HttpHost("localhost", 9200, "http"))
                );

        // 查询索引
        GetIndexRequest request = new GetIndexRequest(("student"));

        GetIndexResponse getIndexResponse =
                null;
        try {
            getIndexResponse = esClient.indices().get(request, RequestOptions.DEFAULT);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (esClient != null) {
                esClient.close();
            }
        }

        // 响应状态
        System.out.println(getIndexResponse.getAliases());
        System.out.println(getIndexResponse.getMappings());
        System.out.println(getIndexResponse.getSettings());



    }
}
